package cn.stylefeng.guns.sys.modular.dbservicedetails.controller;

import cn.stylefeng.guns.base.auth.context.LoginContextHolder;
import cn.stylefeng.guns.base.auth.model.LoginUser;
import cn.stylefeng.guns.base.pojo.page.LayuiPageInfo;
import cn.stylefeng.guns.sys.modular.dbServicelist.model.params.DbServicelistParam;
import cn.stylefeng.guns.sys.modular.dbservicedetails.entity.DbServicedetails;
import cn.stylefeng.guns.sys.modular.dbservicedetails.entity.TableDetails;
import cn.stylefeng.guns.sys.modular.dbservicedetails.model.params.DbServicedetailsParam;
import cn.stylefeng.guns.sys.modular.dbservicedetails.service.DbServicedetailsService;
import cn.stylefeng.roses.core.base.controller.BaseController;
import cn.stylefeng.roses.kernel.model.response.ResponseData;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;


/**
 * 服务详情控制器
 *
 * @author zhaoyiheng
 * @Date 2020-08-21 16:40:40
 */
@Controller
@RequestMapping("/dbServicedetails")
public class DbServicedetailsController extends BaseController {

    private String PREFIX = "/modular/dbServicedetails";

    @Autowired
    private DbServicedetailsService dbServicedetailsService;

    /**
     * 跳转到主页面
     *
     * @author zhaoyiheng
     * @Date 2020-08-21
     */
    @RequestMapping("")
    public String index() {
        return PREFIX + "/dbServicedetails.html";
    }

    /**
     * 新增页面
     *
     * @author zhaoyiheng
     * @Date 2020-08-21
     */
    @RequestMapping("/add")
    public String add() {
        return PREFIX + "/dbServicedetails_add.html";
    }

    /**
     * 编辑页面
     *
     * @author zhaoyiheng
     * @Date 2020-08-21
     */
    @RequestMapping("/edit")
    public String edit() {
        return PREFIX + "/dbServicedetails_edit.html";
    }

    /**
     * 新增接口
     *
     * @author zhaoyiheng
     * @Date 2020-08-21
     */
    @RequestMapping("/addItem")
    @ResponseBody
    public ResponseData addItem(DbServicedetailsParam dbServicedetailsParam) {
        LoginUser user = LoginContextHolder.getContext().getUser();
        this.dbServicedetailsService.add(dbServicedetailsParam, user);
        return ResponseData.success();
    }

    /**
     * 编辑接口
     *
     * @author zhaoyiheng
     * @Date 2020-08-21
     */
    @RequestMapping("/editItem")
    @ResponseBody
    public ResponseData editItem(DbServicedetailsParam dbServicedetailsParam) {
        this.dbServicedetailsService.update(dbServicedetailsParam);
        return ResponseData.success();
    }

    /**
     * 删除接口
     *
     * @author zhaoyiheng
     * @Date 2020-08-21
     */
    @RequestMapping("/delete")
    @ResponseBody
    public ResponseData delete(DbServicedetailsParam dbServicedetailsParam) {
        this.dbServicedetailsService.delete(dbServicedetailsParam);
        return ResponseData.success();
    }

    /**
     * 查看详情接口
     *
     * @author zhaoyiheng
     * @Date 2020-08-21
     */
    @RequestMapping("/detail")
    @ResponseBody
    public ResponseData detail(DbServicedetailsParam dbServicedetailsParam) {
        DbServicedetails detail = this.dbServicedetailsService.getById(dbServicedetailsParam.getId());
        return ResponseData.success(detail);
    }

    /**
     * 查询列表
     *
     * @author zhaoyiheng
     * @Date 2020-08-21
     */
    @ResponseBody
    @RequestMapping("/list")
    public LayuiPageInfo list(DbServicedetailsParam dbServicedetailsParam) {
        return this.dbServicedetailsService.findPageBySpec(dbServicedetailsParam);
    }

    /**
     * 点击表详情单行跳转单表详细页面
     */
    @RequestMapping("/tableDetails")
    public String tableDetails() {
        return PREFIX + "/dbServiceTableDetails.html";
    }


    /**
     * 查询列表
     *
     * @author author
     * @Date 2020-11-02
     */
    @ResponseBody
    @RequestMapping("/getTableDetails")
    public JSONObject getTableDetails(DbServicelistParam param, String tableName, Integer page, Integer limit) {
        return this.dbServicedetailsService.queryTableDetails(param, tableName, page, limit);
    }

}


